<template>
  <div>
    <el-card class="box-card">
      <h2>合同信息查询</h2>
      <el-form :model="searchForm" label-width="120px">
        <el-form-item label="合同名称:">
          <el-input v-model="searchForm.contractName" placeholder="请输入合同名称"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="searchContracts">查询</el-button>
          <el-button @click="resetSearch">重置</el-button>
        </el-form-item>
      </el-form>
      <el-table :data="contracts" style="width: 100%">
        <el-table-column prop="contractId" label="合同ID" width="180"></el-table-column>
        <el-table-column prop="contractName" label="合同名称"></el-table-column>
        <el-table-column prop="status" label="状态"></el-table-column>
      </el-table>
    </el-card>
  </div>
</template>

<script>
export default {
  data() {
    return {
      searchForm: {
        contractName: ''
      },
      contracts: []
    };
  },
  created() {
    this.fetchContracts();
  },
  methods: {
    fetchContracts() {
      this.axios.get('/api/contract/get')
        .then(response => {
          this.contracts = response.data;
        })
        .catch(error => {
          console.error('获取合同信息出错:', error);
        });
    },
    searchContracts() {
      const params = { name: this.searchForm.contractName };
      this.axios.get('/api/contract/search', { params })
        .then(response => {
          this.contracts = response.data;
        })
        .catch(error => {
          console.error('查询合同信息出错:', error);
        });
    },
    resetSearch() {
      this.searchForm.contractName = '';
      this.fetchContracts();
    }
  }
}
</script>

<style scoped>
.box-card {
  margin: auto;
  width: 800px;
}
</style>
